package com.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.FloormanagerMapper;
import com.pojo.Floormanager;
import com.service.FloormanagerService;
import com.vo.FloorManagerVo;
import com.vo.TreeVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class FloormanagerServiceimpl implements FloormanagerService {

    @Resource
    private FloormanagerMapper floormanagerMapper;

    @Override
    public PageInfo<Floormanager> selectallFloor(FloorManagerVo floorManagerVo) {
        PageHelper.startPage(floorManagerVo.getPage(),floorManagerVo.getLimit());
        List<Floormanager> floormanagers = floormanagerMapper.selectallFloor(floorManagerVo);
        PageInfo<Floormanager> pageInfo=new PageInfo<>(floormanagers);
        return pageInfo;
    }

    @Override
    public void insertFloor(Floormanager floormanager) {
        floormanagerMapper.insert(floormanager);
    }

    @Override
    public void updareFloor(Floormanager floorManager) {
        floormanagerMapper.updateByPrimaryKey(floorManager);
    }

    @Override
    public void deleteFloor(Integer id) {
        floormanagerMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<TreeVo> queryTreefloorData(Integer plotid) {
        List<Floormanager> floormanagers = floormanagerMapper.selectFloorByPlotid(plotid);
        List<TreeVo> list =new ArrayList<>();
        for (Floormanager floormanager : floormanagers) {
            TreeVo treeVo=transferTo(floormanager);
            list.add(treeVo);
        }
        return list;
    }

    @Override
    public int selectplotidbyid(Integer id) {
        int selectplotidbyid = floormanagerMapper.selectplotidbyid(id);
        return selectplotidbyid;
    }

    @Override
    public int selectfloorbyplotid(Integer id) {
        int selectfloorbyplotid = floormanagerMapper.selectfloorbyplotid(id);
        return selectfloorbyplotid;
    }

    @Override
    public int selecttotalbyplotid(Integer id) {
        int selecttotalbyplotid = floormanagerMapper.selecttotalbyplotid(id);
        return selecttotalbyplotid;
    }

    public TreeVo transferTo(Floormanager floormanager){
        TreeVo treeVo=new TreeVo();
        treeVo.setId(floormanager.getId());
        treeVo.setTitle(floormanager.getFloorname());
        return treeVo;
    }

























}
